<?php
// +----------------------------------------------------------------------
// | QSCMS
// +----------------------------------------------------------------------
// | Copyright (c)  2025 https://www.qqss.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed QSCMS is not free software, commercial use must purchase official license from official website to avoid unnecessary legal disputes.
// +----------------------------------------------------------------------
// | Author: Contract 990504246@qq.com
// +----------------------------------------------------------------------

namespace app\common\model;

use think\Model;

class GoodsSpecRelation extends Model
{
    // 设置字段信息
    protected $json = ['spec_value'];

    // 关联商品
    public function goods()
    {
        return $this->belongsTo('Goods', 'goods_id');
    }

    // 关联规格
    public function spec()
    {
        return $this->belongsTo('GoodsSpec', 'spec_id');
    }

    // 根据商品ID查询规格
    public function searchGoodsIdAttr($query, $value, $data)
    {
        if (!empty($value)) {
            $query->where('goods_id', $value);
        }
    }
}